package cn.seecoder.courselearning.serviceimpl.course;

import cn.seecoder.courselearning.mapperservice.course.AssignmentMapper;
import cn.seecoder.courselearning.po.course.Assignment;
import cn.seecoder.courselearning.service.course.AssignmenteService;
import cn.seecoder.courselearning.vo.ResultVO;
import cn.seecoder.courselearning.vo.course.AssignmentVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class AssignmentServiceImpl implements AssignmenteService {
    @Resource
    AssignmentMapper mapper;
    @Override
    public List<AssignmentVO> getAssignments(Integer courseId) {

        return mapper.selectByCourseId(courseId);
    }

    @Override
    public ResultVO<AssignmentVO> add(AssignmentVO assignmentVO) {

        Assignment assignment=new Assignment(assignmentVO);
        Integer num=mapper.insert(assignment);
        ResultVO<AssignmentVO> ans=new ResultVO<>(num,num>0?"success":"error");
        return ans;
    }

    @Override
    public ResultVO<AssignmentVO> edit(AssignmentVO assignmentVO) {
        Assignment assignment=new Assignment(assignmentVO);
        Integer num=mapper.update(assignment);
        ResultVO<AssignmentVO> ans=new ResultVO<>(num,num>0?"success":"error");
        return ans;
    }

    @Override
    public ResultVO<AssignmentVO> delete(Integer courseId) {
        Integer num=mapper.delete(courseId);
        ResultVO<AssignmentVO> ans=new ResultVO<>(num,num>0?"success":"error");
        return ans;
    }
}
